<?php

namespace IDock\Insurance\AICS\Request;

use Exception;
use IDock\Insurance\AICS\AICSEnums;
use IDock\Insurance\AICS\Request\AllAICSRequest;
use IDock\Insurance\AICS\Response\FloatRateResponse;
use IDock\Insurance\AICS\Response\UploadFileResponse;
use IDock\Visitor\Premium\PremiumCoverageVisitor;
use IDock\Visitor\Premium\PremiumInquiryVisitor;
use IDock\Visitor\UploadFileVisitor;

class FloatRateRequest extends AllAICSRequest
{
    public $code = 'PriceDiscountService';

    public $envelopeName = 'new:GtePriceDiscountService';

    protected $response = FloatRateResponse::class;

    protected $urlTip = '获取折扣比例';

    /**
     * @var PremiumInquiryVisitor $visitor
     */
    protected $visitor;

    /**
     * @return array
     * @throws Exception
     */
    public function generate(): array
    {
        $damage = 0;
        $coverageList = $this->visitor->getCoverageVisitorList();
        /*** @var PremiumCoverageVisitor $value */
        foreach ($coverageList as $value){
            if($value->coverageCode == 'C02001'){
                $damage = 1;
            }
        }
        return [
            'body' => [
                'CDptCde' => $this->visitor->getExtInfoVisitor()->argc['CDptCde'] ?? '',
                'CProdNo' => $this->visitor->biStartData ? '0364' : '0326',
                'CFstRegYm' => $this->visitor->getVehicleVisitor()->firstRegisterDate,
                'TInsrncBgnTm' => $this->visitor->biStartData ?: $this->visitor->ciStartData,
                'IsContainDamage' => $damage,
                'CFrmNo' => $this->visitor->getVehicleVisitor()->vin,
                'CChgOwnerFlag' => intval(boolval($this->visitor->getVehicleVisitor()->isTransfer)),
            ],
        ];
    }
}
